package operator;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.LongValueSequenceIterator;
import org.apache.flink.util.NumberSequenceIterator;

public class UnionDemo2 {

    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());

        // 有界数据流和无界数据流合并
        DataStreamSource<Long> nums1 = env.fromParallelCollection(new NumberSequenceIterator(1, 10), Long.class);
        DataStreamSource<String> lines = env.socketTextStream("localhost", 8888);
        SingleOutputStreamOperator<Long> nums2 = lines.map(Long::parseLong);
        // 合并
        DataStream<Long> union = nums1.union(nums2);

        union.print();

        env.execute();

    }
}
